<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=iso-8859-1">
<link rel='stylesheet' href='../rurple.css' type='text/css'>
<title>Sorting</title>
</head>
<body>

<h2 class="title">Sorting</h2>
<p><i>Sorting</i>, that is ordering a collection of objects in ascending or descending order, is something that often needs to be done when writing large programs.  In this lesson, you will teach Reeborg some sorting skills.
</p>

<h3 class="section">Sorting two columns</h3>

<p>
As a warming up exercise, write a program so that Reeborg will arrange, or <i>sort</i>, two vertical piles of beepers.  Here are two typical situations:</p>
<p><img alt="sorting start" src="../../images/intro/sort1_start.png">
<img alt="leads to" src="../../images/lead_to.png"><img alt="sorting end" src="../../images/intro/sort1_end.png"></p>
<br />
<br />
<br />
<p><img alt="sorting start" src="../../images/intro/sort2.png">
<img alt="leads to" src="../../images/lead_to.png"><img alt="sorting end" src="../../images/intro/sort2.png"></p>
<p>How difficult would it be to change your program so that the piles are sorted in descending order?</p>

<h3 class="section">Sorting many columns</h3>

<p>The following exercise is quite a bit more challenging.  You have to write a program so that Reeborg will sort an unknown number of vertical piles of beepers into ascending order.  The first empty pile marks the end of the piles that need to be sorted.  Here's a typical example.</p>
<p><img alt="sorting start" src="../../images/intro/sort3_start.png"></p>
<p>
<img alt="leads to" src="../../images/lead_to.png"><img alt="sorting end" src="../../images/intro/sort3_end.png"></p>
<p>How difficult would it be to change your program to sort the piles into descending order?</p>

<center>
<a href="../lessons_toc.htm"><img alt="home"  src="../../images/home.png"></a>

</center>

</body>
</html>